import lombok.extern.slf4j.Slf4j;
import top.yqingyu.qymsg.QyMsg;
import top.yqingyu.qymsg.bean.StringKey;
import top.yqingyu.common.utils.LocalDateTimeUtil;
import top.yqingyu.common.utils.YamlUtil;
import top.yqingyu.trans$client.api.ConnectionConfig;
import top.yqingyu.trans$client.main.ClientAPI;

import java.time.LocalDateTime;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeoutException;

/**
 * @author YYJ
 * @version 1.0.0
 * @ClassName PACKAGE_NAME.a
 * @description
 * @createTime 2023年02月15日 01:37:00
 */
@Slf4j
public class a {

    public static void main(String[] args) throws Exception {
        for (int j = 0; j < 32; j++) {
            new Thread(() -> {
                LocalDateTime now0 = LocalDateTime.now();
                ClientAPI clientAPI = null;
                try {
                    ConnectionConfig build = new ConnectionConfig.Builder(ConnectionConfig.Type.FILE).build();
                    clientAPI = ClientAPI.initSync(build);
                } catch (Exception e) {
                    throw new RuntimeException(e);
                }
                for (int i = 1000; i > 0; i--) {
                    String s = "" + i;
                    try {
                        LocalDateTime now2 = LocalDateTime.now();
                        clientAPI.send(clientAPI.makeStrKey(StringKey.add(s, s + s)));
                    } catch (Exception e) {
                        log.error("", e);
                        throw new RuntimeException(e);
                    }
                }
                log.warn("total cost: {}", LocalDateTimeUtil.between(now0, LocalDateTime.now()));
//        clientAPI.getClient().RCV_MSG_CONTAINER.forEach((a,b)-> System.out.println(b));
                log.warn("not get {}", clientAPI.getClient().RCV_MSG_CONTAINER.size());
                try {
                    clientAPI.shutdown();
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                } catch (CloneNotSupportedException e) {
                    throw new RuntimeException(e);
                }
            }).start();
        }

    }
}
